package com.imu.purse.api.controller;

import com.imu.common.annotation.IgnoreAuth;
import com.imu.common.utils.R;
import com.imu.purse.modules.base.entity.DictInfo;
import com.imu.purse.modules.base.service.DictInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api")
@Api(tags = "版本检测接口")
public class ApiVersionController {

    @Autowired
    private DictInfoService dictInfoService;

    @IgnoreAuth
    @GetMapping("/getNewVersion/{sysType}")
    @ApiOperation("获取最新的版本")
    private R getNewVersion(@PathVariable("sysType") String sysType){
        List<DictInfo> dictList = dictInfoService.findCahceByCode("SYS_VERSION");
        String version = "v1";
        if (!CollectionUtils.isEmpty(dictList)) {
            for (DictInfo dictInfo : dictList) {
                if (sysType.equalsIgnoreCase(dictInfo.getLabel())) {
                    version = "V" + dictInfo.getValue();
                    break;
                }
                if (sysType.equalsIgnoreCase(dictInfo.getLabel())) {
                    version = "V" + dictInfo.getValue();
                    break;
                }

            }

        }
        return R.ok(1).put("version", version);

    }
}
